﻿using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace Selenium
{
    class WebDriver
    {
        private string homePage;

        public string HomePage
        {
            get { return homePage; }
            set { homePage = value; }
        }

        public IWebDriver driver;
        public WebDriver()
        {
            this.driver = new FirefoxDriver();
        }

        public void goToUrl(string url)
        {
            Thread.Sleep(750);
            this.driver.Navigate().GoToUrl(url);
        }
        public IWebDriver switchToWindow(string windowName)
        {
            Thread.Sleep(750);
            IWebDriver webDriver = this.driver.SwitchTo().Window(windowName);
            return webDriver;
        }
        public string getLastWindow()
        {
            return this.driver.WindowHandles.Last();
        }
        public string getFirstWindow()
        {
            return this.driver.WindowHandles.First();
        }
        public IWebDriver switchToFrame(string frameName)
        {
            return this.driver.SwitchTo().Frame(frameName);
        }
        public void close()
        {
            Thread.Sleep(750);
            this.driver.Close();
        }
        public IWebElement findElement(By by)
        {
            Thread.Sleep(750);
            IWebElement webElement = this.driver.FindElement(by);
            return webElement;
        }
        public IWebElement findElement(By by, int index)
        {
            Thread.Sleep(750);
            IWebElement webElement = this.driver.FindElements(by).ElementAt(index);
            return webElement;
        }
    }
}
